package com.dmz.wxcp.wecom.wxbusiness.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dmz.wxcp.wecom.contact.entity.Contact;
import com.dmz.wxcp.wecom.wxbusiness.entity.Article;
import com.dmz.wxcp.wecom.wxbusiness.entity.ReadRecord;
import com.dmz.wxcp.wecom.wxbusiness.entity.TagRecord;
import com.dmz.wxcp.wecom.wxbusiness.mapper.ArticleMapper;
import com.dmz.wxcp.wecom.wxbusiness.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article>
        implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public Integer UpdateArticlePageView(Long id) {
        return articleMapper.upDateArticlePageView(id);
    }

    @Override
    public Integer InsertReadRecord(ReadRecord readRecord) {
        return articleMapper.insertReadRecords(readRecord);
    }

    @Override
    public Integer InsertTagRecord(TagRecord tagRecord) {
        return articleMapper.insertTagRecords(tagRecord);
    }

    public void updatePageViewRecord(Long id, Contact contact){
        this.UpdateArticlePageView(id);
        ReadRecord record=new ReadRecord();
        record.setArticleid(id);
        record.setContactid(contact.getContactId());
        this.InsertReadRecord(record);
    }
}
